const fs = require('fs');
const { devDependencies, name, version } = require('../tmp/package.json');
const deployPkg = require('./package.json');
const config = require('./kuiper.config.js');

for (const pluginName of config.plugins) {
	if (pluginName === name) {
		deployPkg.dependencies[pluginName] = version;
	} else {
		const pkgVersion = devDependencies[pluginName].replace(/^[^0-9.]/g, '');
		deployPkg.dependencies[pluginName] =
			pkgVersion ||
			devDependencies[pluginName] ||
			deployPkg.dependencies[pluginName];
	}
}

fs.writeFileSync('./package.json', JSON.stringify(deployPkg, null, 2));
